package qiyu.im.core.server;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created with IntelliJ IDEA.
 * Description: 这边客户端类似于创建10个客户端同时并发的效果
 * User: sfx
 * Date: 2023-10-16
 * Time: 17:32
 */
public class bioClient {

    public static void main(String[] args) throws InterruptedException {
        AtomicInteger atomicInteger = new AtomicInteger(0);
        CountDownLatch latch = new CountDownLatch(1);
        for(int i = 0;i < 10; ++ i) {
            new Thread(() -> {
                try {
                    Socket socket = new Socket();
                    latch.await();
                    // 连接9090端口
                    socket.connect(new InetSocketAddress(9090));
                    System.out.println("连接已经建立完成 : " + atomicInteger.getAndIncrement());
                } catch (IOException | InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }).start();
        }
        latch.countDown();
        Thread.sleep(1000000);
    }
}